<%
var headerPart = {
%>
<script type="text/javascript">
    function page(n,s){
        $("#pageNo").val(n);
        $("#pageSize").val(s);
        $("#searchForm").submit();
        return false;
    }
</script>
<% }; %>
<% layout("/layouts/micro.html",{headerSection:headerPart}){ %>
<div class="layui-fluid">
	<div class="layui-card">
	<!--<div class="layui-tab layui-tab-brief childrenBody">
	<ul class="layui-tab-title">
		<li class="layui-this"><a href="${ctx}/sys/dict/">字典列表</a></li>
		<%if(shiro.hasPermission("sys:dict:edit")){%><li><a href="${ctx}/sys/dict/form?sort=10">字典添加</a></li><%}%>
	</ul>
 	<div class="layui-tab-content">-->
	<form id="searchForm" action="${ctx}/sys/dict/" method="post" class="layui-form layui-card-header layuiadmin-card-header-auto">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">类型：</label>
				<div class="layui-input-block">
					<select id="type" name="type" class="input-medium">
						<option value="" label=""/>
						<%for(type in typeList){%>
						<option value="${type}" label="${type}">${type}</option>
						<%}%>
					</select>
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">描述：</label>
				<div class="layui-input-block">
					<input type="text" name="description" htmlEscape="false" maxlength="200" class="layui-input"/>
				</div>
			</div>
			<div class="layui-inline">
				<button class="layui-btn layuiadmin-btn-useradmin" lay-submit="" lay-filter="LAY-enrollList-search">
					<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
				</button>
			</div>
		</div>
	</form>
		<div class="layui-card-body">
			<#message content="${message!}"/>
			<%if(shiro.hasPermission("sys:dict:edit")){%>
			<div>
				<button class="layui-btn layui-btn-normal LAY_ADD_dict_btn"><i class="layui-icon layui-icon-add-1"></i>字典添加</button>
			</div>
			<%}%>
			<table class="layui-table" >
				<thead><tr><th>键值</th><th>标签</th><th>类型</th><th>描述</th><th>排序</th><%if(shiro.hasPermission("sys:dict:edit")){%><th>操作</th><%}%></tr></thead>
				<tbody>
				<%for(dict in page.list){%>
					<tr>
						<td>${dict.value}</td>
						<td><a href="${ctx}/sys/dict/form?id=${dict.id}">${dict.label}</a></td>
						<td><a href="javascript:" onclick="$('#type').val('${dict.type}');$('#searchForm').submit();return false;">${dict.type}</a></td>
						<td>${dict.description}</td>
						<td>${dict.sort}</td>
						<%if(shiro.hasPermission("sys:dict:edit")){%><td>
							<a class="layui-btn layui-btn-xs" onclick="editDict('${dict.id}')"  href="javascript:void(0);">修改</a>
							<a class="layui-btn layui-btn-xs" onclick="addDictValue('${dict.type}','${dict.sort+10}','${dict.description}')"  href="javascript:void(0);">添加键值</a>
							<a class="layui-btn layui-btn-xs layui-btn-danger"  href="${ctx}/sys/dict/delete?id=${dict.id}&type=${dict.type}" onclick="return confirmx('确认要删除该字典吗？', this.href)">删除</a>
						</td>
						<%}%>
					</tr>
				<%}%>
				</tbody>
			</table>
			<div class="pagination">${page}</div>
		</div>
	</div>
</div>
<script>
    layui.use(['form','layer'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;
        //添加
        $(".LAY_ADD_dict_btn").click(function(){
            var index = layui.layer.open({
                title : "添加字典",
                type : 2,
                content : "${ctx}/sys/dict/form?sort=10",
                maxmin: true,
                area: ['800px', '500px'],
                btn: ['确定', '取消'],
                yes: function(index, layero){
                    var submit = layero.find('iframe').contents().find('#dictForm');
                    submit.trigger('click');
                    layer.close(index);
                },
                end:function(){
                    location.reload();
                }
            })
        })
    })
    var editDict = function(id){
        var index = layui.layer.open({
            title : "修改字典",
            type : 2,
            content : "${ctx}/sys/dict/form?id="+id,
            maxmin: true,
            area: ['800px', '500px'],
            btn: ['确定', '取消'],
            yes: function(index, layero){
                var submit = layero.find('iframe').contents().find('#dictForm');
                submit.trigger('click');
                layer.close(index);
            },
            end:function(){
                location.reload();
            }
        })
    }
    var addDictValue = function(type,sort,desc){
        var index = layui.layer.open({
            title : "添加键值",
            type : 2,
            content : "${ctx}/sys/dict/form?type="+type+"&sort="+sort+"&description="+desc,
            maxmin: true,
            area: ['800px', '500px'],
            btn: ['确定', '取消'],
            yes: function(index, layero){
                var submit = layero.find('iframe').contents().find('#dictForm');
                submit.trigger('click');
                layer.close(index);
            },
            end:function(){
                location.reload();
            }
        })
    }
</script>
<%}%>